package strangeattractor.UI;

import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.SwingConstants;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import strangeattractor.core.Transformer;
import strangeattractor.equations.Lorenz;
import strangeattractor.equations.Pickover;

public class PickoverModifier extends EquationModifier {

	private Pickover equation;
	private JSlider sliderA;
	private JSlider sliderB;
	private JSlider sliderC;
	private JSlider sliderD;
	
	public PickoverModifier(){
		super();
		this.center.gen.zoom(100);
	}

	@Override
	protected void fill(JPanel equationModifierPanel) {
		initializeA(equationModifierPanel);
		initializeB(equationModifierPanel);
		initializeC(equationModifierPanel);
		initializeD(equationModifierPanel);
	}

	private void initializeD(JPanel equationModifierPanel) {
		this.sliderD = new JSlider(0, 60000);
		sliderD.setOrientation(SwingConstants.VERTICAL);
		sliderD.setValue(60000);
		equationModifierPanel.add(sliderD);
		sliderD.addChangeListener(new ChangeListener() {

			@Override
			public void stateChanged(ChangeEvent arg0) {
				equation.D = (((double) sliderD.getValue()) / 10000 - 3);
				center.preview(center.getSize());
			}

		});
	}

	private void initializeC(JPanel equationModifierPanel) {
		this.sliderC = new JSlider(0, 60000);
		sliderC.setOrientation(SwingConstants.VERTICAL);
		sliderC.setValue(60000);
		equationModifierPanel.add(sliderC);
		sliderC.addChangeListener(new ChangeListener() {

			@Override
			public void stateChanged(ChangeEvent arg0) {
				equation.C = (((double) sliderC.getValue()) / 10000 - 3);
				center.preview(center.getSize());
			}

		});
	}

	private void initializeB(JPanel equationModifierPanel) {
		this.sliderB = new JSlider(0, 60000);
		sliderB.setOrientation(SwingConstants.VERTICAL);
		sliderB.setValue(60000);
		equationModifierPanel.add(sliderB);
		sliderB.addChangeListener(new ChangeListener() {

			@Override
			public void stateChanged(ChangeEvent arg0) {
				equation.B = (((double) sliderB.getValue()) / 10000 - 3);
				center.preview(center.getSize());
			}

		});
	}

	private void initializeA(JPanel equationModifierPanel) {
		this.sliderA = new JSlider(0, 60000);
		sliderA.setOrientation(SwingConstants.VERTICAL);
		sliderA.setValue(60000);
		equationModifierPanel.add(sliderA);
		sliderA.addChangeListener(new ChangeListener() {

			@Override
			public void stateChanged(ChangeEvent arg0) {
				try {
					equation.A = (((double) sliderA.getValue()) / 10000 - 3);
					center.preview(center.getSize());
				} catch (Throwable t) {
					t.printStackTrace();
				}
			}

		});
	}

	@Override
	protected Transformer initializeEquation() {
		this.equation = new Pickover(3, 3, 3, 3);
		return equation;
	}

}
